---
title: Get All Annotations
description: Learn how to retrieve all annotations from every page in a document, with progress updates.
searchable: true
---

# getAllAnnotations

Retrieves all annotations from every page in the document.

## Signature

```typescript
getAllAnnotations(
  doc: PdfDocumentObject
): PdfTask<Record<number, PdfAnnotationObject[]>, PdfAnnotationsProgress>;
````

## Description

This method iterates through the entire document to collect all annotations. Because this can be a long-running operation for large documents, it is designed to provide progress updates.

You can use the `.onProgress()` callback to receive annotations for each page as soon as they are processed, allowing you to update your UI incrementally.

## Parameters

| Name | Type | Description |
| :--- | :--- | :--- |
| **`doc`** | `PdfDocumentObject` | The handle of the document to retrieve annotations from. |

## Returns

`PdfTask<Record<number, PdfAnnotationObject[]>, PdfAnnotationsProgress>`

A **`Task`** with two payloads: a final result and a progress update.

  - **Resolved Value**: The task resolves with a `Record<number, PdfAnnotationObject[]>`, which is an object mapping each page index to its array of annotations.
  - **Progress Payload**: While processing, the task emits progress updates of type `PdfAnnotationsProgress` (`{ page: number; annotations: PdfAnnotationObject[] }`) for each page.

See [Concepts: Tasks](./tasks.md) for details on handling progress.

## Example

```typescript
// Assuming 'engine' and an open 'document' object are available

function loadAllAnnotations(doc) {
  const allAnnotationsTask = engine.getAllAnnotations(doc);

  // Listen for progress to update the UI incrementally
  allAnnotationsTask.onProgress(progress => {
    console.log(`Received ${progress.annotations.length} annotations for page ${progress.page}.`);
    // You could render these annotations now
  });

  // Handle the final result
  allAnnotationsTask.toPromise().then(allAnnosByPage => {
    console.log('Finished loading all annotations!');
    const total = Object.values(allAnnosByPage).reduce((sum, annos) => sum + annos.length, 0);
    console.log(`Total annotations in document: ${total}`);
  }).catch(error => {
    console.error('Failed to get all annotations:', error);
  });
}
```

## See Also

  - [Get Page Annotations](./get-page-annotations.md)